package me.jollyfly.jshop.item.client.model

import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import java.io.Serializable
import java.util.*
import javax.persistence.Entity
import javax.persistence.GeneratedValue
import javax.persistence.GenerationType
import javax.persistence.Id
import javax.persistence.Table
import javax.persistence.Transient

/**
 * @author jollyfly
 * *
 * @date 2017/9/25
 * *
 * @description
 */

@Entity
@Table(name = "tb_item_category")
@JsonIgnoreProperties(ignoreUnknown = true)
class ItemCategoryDO : Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "Mysql")
    var id: Long? = null

    var parentId: Long? = null

    var name: String? = null

    var status: Int? = null

    var sortOrder: Int? = null

    var asParent: Boolean? = null

    var url: String? = null

    var created: Date? = null

    var updated: Date? = null


    @Transient
    var children: MutableList<ItemCategoryDO>? = null

    init {
        children = ArrayList<ItemCategoryDO>()
    }


    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (other !is ItemCategoryDO) return false

        if (id != other.id) return false
        if (parentId != other.parentId) return false
        if (name != other.name) return false
        if (status != other.status) return false
        if (sortOrder != other.sortOrder) return false
        if (asParent != other.asParent) return false
        if (url != other.url) return false
        if (created != other.created) return false
        if (updated != other.updated) return false
        if (children != other.children) return false

        return true
    }

    override fun hashCode(): Int {
        var result = id?.hashCode() ?: 0
        result = 31 * result + (parentId?.hashCode() ?: 0)
        result = 31 * result + (name?.hashCode() ?: 0)
        result = 31 * result + (status ?: 0)
        result = 31 * result + (sortOrder ?: 0)
        result = 31 * result + (asParent?.hashCode() ?: 0)
        result = 31 * result + (url?.hashCode() ?: 0)
        result = 31 * result + (created?.hashCode() ?: 0)
        result = 31 * result + (updated?.hashCode() ?: 0)
        result = 31 * result + (children?.hashCode() ?: 0)
        return result
    }

    override fun toString(): String {
        return "ItemCategoryDO(id=$id, parentId=$parentId, name=$name, status=$status, sortOrder=$sortOrder, asParent=$asParent, url=$url, created=$created, updated=$updated, children=$children)"
    }


}
